package com.example.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.dao.GoodsAdminDao;
import com.example.entity.PageResult;
import com.example.entity.QueryPageBean;
import com.example.pojo.Goods;
import com.example.pojo.GoodsCategory;
import com.example.service.GoodsAdminService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service(interfaceClass = GoodsAdminService.class)
public class GoodsAdminServiceImpl implements GoodsAdminService {
    @Autowired
    private GoodsAdminDao goodsAdminDao;
    @Override
    public PageResult findpage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<Goods> page = goodsAdminDao.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Goods goods) {
        goods.setGmtCreate(new Date());
        goods.setGmtModify(new Date());
        goodsAdminDao.add(goods);
    }

    @Override
    public void deleteById(Integer id) {
        goodsAdminDao.deleteById(id);
    }

    @Override
    public Goods findById(Integer id) {
        return goodsAdminDao.findById(id);
    }

    @Override
    public void edit(Goods goods) {
        goods.setGmtModify(new Date());
        goodsAdminDao.edit(goods);
    }

    @Override
    public List<Goods> getAll() {
return goodsAdminDao.findAllGoods();
    }

    ;
}
